﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iCooker.NET.Core.DataTransferObjects;
using iCooker.NET.Core.Services.Interfaces;

namespace iCooker.NET.Tests.MockServices
{
    public class MockRecipeService : IRecipeService
    {
        List<Recipe> _list;

        #region Ctor;
        public MockRecipeService()
            {
                _list = new List<Recipe>();
                for (int i = 0; i < 20; i++)
                {
                    Recipe _tempRecipe = new Recipe(){ Id= i , Author = "Jimmy "+i.ToString() , Description = "Description" + i.ToString() , Created = DateTime.Now , Guid = new Guid() };
                    _list.Add(_tempRecipe);

                }
            }
        #endregion

        #region IRecipeService Members

        public void Add(iCooker.NET.Core.DataTransferObjects.Recipe recipe)
        {
            _list.Add(recipe);
        }

        public void Update(iCooker.NET.Core.DataTransferObjects.Recipe recipe)
        {
           Recipe _recipeToUpdate =  _list.Where(x => x.Id == recipe.Id).SingleOrDefault();
           _recipeToUpdate = recipe;
           _list.RemoveAt(recipe.Id);
           _list.Add(_recipeToUpdate);
        }

        public void Delete(iCooker.NET.Core.DataTransferObjects.Recipe recipe)
        {
            _list.RemoveAt(recipe.Id);
        }

        public IQueryable<iCooker.NET.Core.DataTransferObjects.Recipe> GetAll()
        {
            return _list.AsQueryable();
        }

        public iCooker.NET.Core.DataTransferObjects.Recipe GetById(int index)
        {
            return _list.Where(x => x.Id == index).SingleOrDefault();
        }

        #endregion
    }
}
